/**
 * API配置文件
 * 包含不同环境的API配置
 */

// 环境判断
const isDevelopment = process.env.NODE_ENV === 'development'
const isProduction = process.env.NODE_ENV === 'production'

// 不同环境的配置
const config = {
  development: {
    // 开发环境配置
    baseURL: '/api', // 使用代理前缀，通过vite代理到https://blue.trading-code.com
    timeout: 10000,
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  },
  production: {
    // 生产环境配置
    baseURL: '', // 生产环境API地址
    timeout: 15000,
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  }
}

// 根据环境选择配置
export const API_CONFIG = isDevelopment ? config.development : config.production

// API接口地址常量
export const API_ENDPOINTS = {
  // 用户相关
  USER: {
    LOGIN: '/user/login',
    LOGOUT: '/user/logout',
    INFO: '/user/info',
    GET: '/app-api/member/user/get',
    UPDATE: '/app-api/member/user/update',
    UPDATE_EMAIL: '/app-api/member/user/update-email',
    UPDATE_LANG: '/app-api/member/user/update-lang',
    REGISTER: '/user/register',
    UPDATE_PROFILE: '/user/profile',
    CHANGE_PASSWORD: '/app-api/member/user/update-password',
    CHANGE_PAY_PASSWORD: '/app-api/member/user/update-pay-password',
    CREATE_PAY_PASSWORD: '/app-api/member/user/create-pay-password'
  },
  
  // 认证相关
  AUTH: {
    SEND_MAIL_CODE: '/app-api/member/auth/send-mail-code',
    USER_AUTH_STATUS: '/app-api/member/auth/user-auth-status'
  },
  
  // 收益相关
  INCOME: {
    GET: '/app-api/option/income/get',
    GET_PROFIT: '/app-api/invest/income-record/get-profit'
  },
  
  // 投资相关
  INVEST: {
    GET_PROFIT: '/app-api/invest/income-record/get-profit', // 获取量化收益数据
    PRODUCTS_CATEGORY_LIST: '/app-api/invest/products-category/list', // 获取产品分类列表
    PRODUCTS_PAGE: '/app-api/invest/products/page', // 获取投资品分页数据
    PRODUCTS_GET: '/app-api/invest/products/get' // 获取产品详情
  },
  
  // 投资相关
  INVESTMENT: {
    LIST: '/app-api/investment/list',
    DETAIL: '/app-api/investment/detail',
    CREATE: '/app-api/investment/create',
    UPDATE: '/app-api/investment/update',
    DELETE: '/app-api/investment/delete'
  },

  // 期权订单相关
  OPTION: {
    ORDER_PAGE: '/app-api/option/order/page', // 获取持仓订单分页数据
    ORDER_GET: '/app-api/option/order/get', // 获取订单详情
    ORDER_SUBMIT: '/app-api/option/order/submit', // 提交下单
    ORDER_FEE: '/app-api/option/order/fee' // 获取订单手续费
  },
  
  // 行情相关
  MARKET: {
    QUOTES: '/market/quotes',
    HISTORY: '/market/history',
    REALTIME: '/market/realtime'
  },
  
  // 持仓相关
  POSITION: {
    LIST: '/position/list',
    DETAIL: '/position/detail',
    BUY: '/position/buy',
    SELL: '/position/sell'
  },
  
  // 量化相关
  QUANTITATIVE: {
    STRATEGIES: '/quantitative/strategies',
    BACKTEST: '/quantitative/backtest',
    PERFORMANCE: '/quantitative/performance'
  },
  
  // 质押相关
  PLEDGE: {
    ORDER_PAGE: '/app-api/invest/pledge-order/page',
    ORDER_DETAIL: '/app-api/invest/pledge-order/get'
  },
  
  // 充值相关
  RECHARGE: {
    ORDER_PAGE: '/app-api/member/recharge/page'
  },
  
  // TRON订单相关
  TRON_ORDER: {
    CREATE: '/app-api/member/tron-order/create',
    GET_BY_ORDER: '/app-api/member/tron-order/get-by-order'
  },
  
  // 提现相关
  WITHDRAW: {
    ORDER_PAGE: '/app-api/member/withdraw/page',
    CREATE: '/app-api/member/withdraw/create' // 提现申请接口
  },
  
  // 钱包地址相关
  WALLET_ADDRESS: {
    PAGE: '/app-api/member/wallet-address/page', // 钱包地址分页接口
    CREATE: '/app-api/member/wallet-address/create', // 创建钱包地址
    UPDATE: '/app-api/member/wallet-address/update', // 更新钱包地址
    DELETE: '/app-api/member/wallet-address/delete' // 删除钱包地址
  },
  
  // 文件上传
  UPLOAD: {
    IMAGE: '/upload/image',
    FILE: '/upload/file'
  },
  
  // FAQ相关
  FAQ: {
    LIST: '/app-api/journalism/content/page',
    DETAIL: '/app-api/journalism/content/get',
    SEARCH: '/app-api/journalism/content/search'
  },
  
  // 邀请相关
  INVITE: {
    PROFIT_SUMMARY: '/app-api/member/invite-profit/summary',
    PROFIT_PAGE: '/app-api/member/invite-profit/page',
    TOTAL_PROFIT_RANK: '/app-api/member/invite-profit/total-profit-rank'
  },
  
  // 消息相关
  MESSAGE: {
    MY_PAGE: '/app-api/system/notify-message/my-page', // 站内信分页列表
    UPDATE_READ: '/app-api/system/notify-message/update-read' // 更新消息已读状态
  },
  
  // 商品相关
  GOODS: {
    LIST: '/app-api/goods/list', // 获取商品列表
    DETAIL: '/app-api/goods/detail', // 获取商品详情
    STOCK_PAGE: '/app-api/goods/stock/page', // 获得产品管理分页
    STOCK_GET: '/app-api/goods/stock/get', // 获得产品管理详情
    STOCK_KLINE: '/app-api/goods/stock/get-stock-kline', // 获得产品K线数据
    STOCK_COMMON_KLINE: '/app-api/goods/stock/get-common-kline', // 获取常用K线数据
    STOCK_FAVORITES_CREATE: '/app-api/goods/stock-favorites/create', // 创建收藏
    STOCK_FAVORITES_DELETE: '/app-api/goods/stock-favorites/delete', // 删除收藏
    STOCK_CONFIG_LIST: '/app-api/goods/stock-config/get-list-by-product' // 根据产品获取配置列表
  }
}

// 请求状态码
export const HTTP_STATUS = {
  SUCCESS: 200,
  CREATED: 201,
  NO_CONTENT: 204,
  BAD_REQUEST: 400,
  UNAUTHORIZED: 401,
  FORBIDDEN: 403,
  NOT_FOUND: 404,
  INTERNAL_SERVER_ERROR: 500,
  BAD_GATEWAY: 502,
  SERVICE_UNAVAILABLE: 503
}

// WebSocket配置
export const WS_CONFIG = {
  development: {
    baseUrl: 'wss://dev.wbaix.com/infra/ws', // 开发环境WebSocket地址
    timeout: 10000
  },
  production: {
    baseUrl: 'wss://api.wbaix.com/infra/ws', // 生产环境WebSocket地址
    timeout: 15000
  }
}

// 获取当前环境WebSocket配置
export const getWebSocketConfig = () => {
  return isDevelopment ? WS_CONFIG.development : WS_CONFIG.production
}

// 业务状态码
export const BUSINESS_CODE = {
  SUCCESS: 0,
  ERROR: -1,
  TOKEN_EXPIRED: 401,
  PERMISSION_DENIED: 403,
  VALIDATION_ERROR: 422
}

export default {
  API_CONFIG,
  API_ENDPOINTS,
  HTTP_STATUS,
  BUSINESS_CODE
}